// @algorithm @lc id=128 lang=cpp 
// @title longest-consecutive-sequence


// @test([100,4,200,1,3,2])=4
// @test([0,3,7,2,5,8,4,6,0,1])=9
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        if(nums.size() < 2) return nums.size();
        unordered_set<int> exist;
        for(auto & t : nums)
            exist.insert(t);
        int ans = 0;
        for(auto t : nums){
            if(exist.count(t-1)) continue;
            int s = t;
            while(exist.count(++t));
            ans = max(ans, t-s);
        }
        return ans;
    }
};